import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QTabWidget, QWidget, QVBoxLayout, QTabBar


class NoBorderTabWidget(QTabWidget):
    def __init__(self, parent=None):
        super(NoBorderTabWidget, self).__init__(parent)
        self.setTabShape(QTabWidget.Triangular)

        self.tab_bar = QTabBar()
        self.setStyleSheet("{margin-left: 100px; background-color:red;}")
        self.tab_bar.setDocumentMode(True)
        self.tab_bar.setTabsClosable(True)
        self.setTabBar(self.tab_bar)

    def tabBar(self):
        return self.tab_bar


def main():
    app = QApplication(sys.argv)
    app.setStyle('Fusion')

    tab_widget = NoBorderTabWidget()
    tab_widget.addTab(QWidget(), "Tab 1")
    tab_widget.addTab(QWidget(), "Tab 2")

    tab_widget.tabBar().setStyle(app.style())

    layout = QVBoxLayout()
    layout.addWidget(tab_widget)

    # 设置窗口属性以创建无边框窗口
    # tab_widget.setWindowFlags(tab_widget.windowFlags() | Qt.FramelessWindowHint)
    # tab_widget.setAttribute(Qt.WA_TranslucentBackground)

    tab_widget.resize(1024, 768)
    tab_widget.show()

    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
